﻿//     Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.Gateway.Configuration
{
    public static class Helpers
    {
        public static bool SafeEqualsCI(this string lhs, string rhs)
        {
            return SafeEquals(lhs, rhs, (item1, item2) => item1.Equals(item2, StringComparison.OrdinalIgnoreCase));
        }

        public static bool SafeEquals<T>(this T lhs, T rhs)
        {
            return SafeEquals(lhs, rhs, (item1, item2) => EqualityComparer<T>.Default.Equals(item1, item2));
        }

        public static bool SafeEquals<T>(this T lhs, T rhs, Func<T, T, bool> comparitor)
        {
            if (lhs == null && rhs == null)
            {
                return true;
            }
            else if (lhs == null || rhs == null)
            {
                return false;
            }
            return comparitor(lhs, rhs);
        }
    }
}
